package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCBorrowReplacementRMAInfo;
import com.shrct.businessprocess.customerservice.RCFaultReport;
import com.shrct.businessprocess.customerservice.RCFaultReportProduct;
import com.shrct.businessprocess.customerservice.impl.RCFaultReportRMAInfoImpl;
import com.shrct.businessprocess.customerservice.proxy.RCBorrowReplacementRMAInfoProxy;
import com.shrct.businessprocess.product.RCIdentifiablePhysicalProductEntry;
import com.shrct.businessprocess.product.RCLogicProduct;
import com.shrct.businessprocess.product.RCRMABorrowReplacementEvent;
import com.shrct.businessprocess.product.impl.RCIdentifiablePhysicalProductEntryImpl;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@Entity
@DiscriminatorValue("RCBORROWREPLACEMENTRMAINFO_TYPE")
public class RCBorrowReplacementRMAInfoImpl extends RCFaultReportRMAInfoImpl implements RCBorrowReplacementRMAInfo {
  public RCBorrowReplacementRMAInfoImpl() {
    super();
  }
  
  public RCBorrowReplacementRMAInfoImpl(final RCFaultReportProduct product) {
    super( product);
    
  }
  
  @JoinColumn(name = "toProduct_id")
  @ManyToOne(targetEntity = RCIdentifiablePhysicalProductEntryImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCIdentifiablePhysicalProductEntry toProduct;
  
  public RCIdentifiablePhysicalProductEntry getToProduct() {
    return this.toProduct;
  }
  
  public RCBorrowReplacementRMAInfo setToProduct(final RCIdentifiablePhysicalProductEntry toProduct) {
    this.toProduct = toProduct;
    return this;			
    
  }
  
  private String newSid;
  
  public String getNewSid() {
    return this.newSid;
  }
  
  public RCBorrowReplacementRMAInfo setNewSid(final String newSid) {
    this.newSid = newSid;
    return this;			
    
  }
  
  public String getEventTitle() {
    return "\u501F\u7528RMA";
  }
  
  public String getEventDetailInfo() {
    String _plus = ("\u65B0\u8BBE\u5907\u5E8F\u5217\u53F7:" + this.newSid);
    String _plus_1 = (_plus + ",\u501F\u7528\u8BBE\u5907\u5E8F\u5217\u53F7:");
    String _sid = this.toProduct.getSid();
    String _plus_2 = (_plus_1 + _sid);
    return _plus_2;
  }
  
  public void commit(final Date date) {
    RCFaultReportProduct _product = this.getProduct();
    RCIdentifiablePhysicalProductEntry _product_1 = _product.getProduct();
    RCLogicProduct _logicProduct = _product_1.getLogicProduct();
    RCRMABorrowReplacementEvent _recordBorrowReplacementRMA = _logicProduct.recordBorrowReplacementRMA(date, this.newSid, this.toProduct);
    final Procedure1<RCRMABorrowReplacementEvent> _function = new Procedure1<RCRMABorrowReplacementEvent>() {
        public void apply(final RCRMABorrowReplacementEvent it) {
          Date _newItemArriveDate = RCBorrowReplacementRMAInfoImpl.this.getNewItemArriveDate();
          it.setNewItemArriveDate(_newItemArriveDate);
          Date _newItemInstallDate = RCBorrowReplacementRMAInfoImpl.this.getNewItemInstallDate();
          it.setNewItemInstallDate(_newItemInstallDate);
          Date _badItemReceiveDate = RCBorrowReplacementRMAInfoImpl.this.getBadItemReceiveDate();
          it.setBadItemReceiveDate(_badItemReceiveDate);
          Date _badItemReturnDate = RCBorrowReplacementRMAInfoImpl.this.getBadItemReturnDate();
          it.setBadItemReturnDate(_badItemReturnDate);
          String _supplierName = RCBorrowReplacementRMAInfoImpl.this.getSupplierName();
          it.setSupplierName(_supplierName);
          String _rmaNumber = RCBorrowReplacementRMAInfoImpl.this.getRmaNumber();
          it.setRmaNumber(_rmaNumber);
          String _caseNumber = RCBorrowReplacementRMAInfoImpl.this.getCaseNumber();
          it.setCaseNumber(_caseNumber);
          String _comment = RCBorrowReplacementRMAInfoImpl.this.getComment();
          it.setComment(_comment);
        }
      };
    ObjectExtensions.<RCRMABorrowReplacementEvent>operator_doubleArrow(_recordBorrowReplacementRMA, _function);
    this.setIsFinished(Boolean.valueOf(true));
    RCFaultReportProduct _product_2 = this.getProduct();
    RCFaultReport _faultReport = _product_2.getFaultReport();
    RCFaultReportProduct _product_3 = this.getProduct();
    _faultReport.finishDeviceRMA(_product_3, "\u5B8C\u6210\u501F\u7528\u8BBE\u5907RMA");
  }
  
  public static RCBorrowReplacementRMAInfo create(final RCFaultReportProduct product, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.customerservice.RCBorrowReplacementRMAInfo rCBorrowReplacementRMAInfo = new com.shrct.businessprocess.customerservice.impl.RCBorrowReplacementRMAInfoImpl(
    	product
    );
    objectFactory.create(rCBorrowReplacementRMAInfo);
    return rCBorrowReplacementRMAInfo;			
    
  }
  
  public static RCBorrowReplacementRMAInfo createRCBorrowReplacementRMAInfoImpl(final RCFaultReportProduct product, final IObjectFactory objectFactory, final Procedure1<RCBorrowReplacementRMAInfo> init) {
    com.shrct.businessprocess.customerservice.RCBorrowReplacementRMAInfo rCBorrowReplacementRMAInfo = new com.shrct.businessprocess.customerservice.impl.RCBorrowReplacementRMAInfoImpl(
    	product
    );
    objectFactory.create(rCBorrowReplacementRMAInfo);
    init.apply(rCBorrowReplacementRMAInfo);
    
    return rCBorrowReplacementRMAInfo;			
    
  }
  
  public RCBorrowReplacementRMAInfoProxy toProxy() {
    com.shrct.businessprocess.customerservice.proxy.RCBorrowReplacementRMAInfoProxy proxy = new com.shrct.businessprocess.customerservice.proxy.RCBorrowReplacementRMAInfoProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
